package com.jiyinit.web.core.business.dao;

import com.jiyinit.core.framework.base.paging.PagingResult;
import com.jiyinit.core.framework.dao.mybatis.base.MybatisDaoContext;
import com.jiyinit.core.framework.dao.mybatis.paginator.domain.PageBounds;
import com.jiyinit.web.core.business.dto.FunctionPageRequest;
import com.jiyinit.web.core.business.entity.TabCoreFunEntity;
import com.jiyinit.web.core.business.entity.TabOrgFunEntity;
import com.jiyinit.web.core.business.enums.CommonEnum;
import com.jiyinit.web.core.business.vo.FunctionVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.beans.IntrospectionException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * <p></p>
 * <p/>
 * <PRE>
 * <BR>	修改记录
 * <BR>-----------------------------------------------
 * <BR>	修改日期			修改人			修改内容
 * </PRE>
 *
 * @author changly
 * @version 1.0
 * @date 2017/4/11 17:51
 * @since 1.0
 */
@Repository("core.tabOrgFunDao")
public class TabOrgFunDao {

    /**
     * 日志对象
     */
    private static Logger logger = LoggerFactory.getLogger(TabOrgFunDao.class);

    private String SQLID = "org.function.";

    @Autowired
    @Qualifier("core.MybatisDaoContext")
    private MybatisDaoContext mybatisDaoContext;


    public int delete(Integer orgId,Integer userId){
        HashMap<String,Object> params = new HashMap<>();
        params.put("orgId",orgId);
        params.put("userId",userId);
       return mybatisDaoContext.update(SQLID+"delete",params);
    }

    public int bacthsave(Integer orgId,Integer[] funIds,Integer userId){
        if(funIds == null) return 0;
        List<TabOrgFunEntity> list = new ArrayList<>();
        for(Integer funId : funIds){
            TabOrgFunEntity fun = new TabOrgFunEntity();
            fun.setIsDelete(CommonEnum.IsDelete.COMMON.getCode());
            fun.setOrgId(orgId);
            fun.setFunId(funId);
            fun.setCreateId(userId);
            fun.setCreateTime(new Date());
            list.add(fun);
        }
        return mybatisDaoContext.batchSave(SQLID+"insertSelective",list);
    }

    public List<TabOrgFunEntity> findFunctionByOrg(Integer orgId){
        return mybatisDaoContext.findAll(SQLID+"findFunctionByOrg",TabOrgFunEntity.class,orgId);
    }
}
